<style>
	body{
		background: #f5f5f5;
	}
</style>
<div class="sectionY">
	<a href="javascript:history.back()">
		<img src="__PUBLIC__/home/images/a4.png" class="a1" alt="">
	</a>
	<p class="p1">资产出售</p>
</div>
<div class="kong1"></div>
<div class="neng_section1">
	<p class="p1">提醒:</p>
	<p class="p2">您当前有{$userinfo.pushs}，每日只允许出售资产15次 </p>
</div>
<div class="neng_section2">
	<div class="neng_section2_1">
		<form action="">
			<div class="f1 clearfix">
				<p class="p1">资产类型</p>
				<p class="p2">推广收益({$userinfo.pushs})</p>
			</div>
			<div class="f1 clearfix">
				<p class="p1">兑换资产</p>
				<input type="number" name='salary'  class="input1 input_plc" placeholder="请输入出售数量">
			</div>
			<div class="f1 clearfix">
				<p class="p1">交易密码</p>
				<input type="password" name='pwd' class="input1 input_plc" placeholder="请输入交易密码">
			</div>
			<div class="sub">
				<button type="button" id="sub">确认出售</button>
				<p class="p1">提示：请先通过实名认证再进行转赠</p>
			</div>
		</form>
	</div>
</div>
<script>
	$(function(){
        $('#sub').click(function(){
            var num = $('input[name=salary]').val();
            var pwd = $('input[name=pwd]').val();
            if(num=='' || num<{:config('setting.recommendprice')}){
                layer.alert('请检查您要出售的资产数量，资产出售不能低于低于{:config("setting.recommendprice")}！',{icon: 2,shade:0.8,title:"错误提示:"});return false;
            }
            if(pwd==''){
                layer.alert('请输入交易密码！',{icon: 2,shade:0.8,title:"错误提示:"});return false;
            }
            $.ajax({
    			type: 'POST',
    			url: "{:url('Set/sale_create_order')}",
    			dataType: "html",
    			data: "num="+num+"&pwd="+pwd,
    			success:function(responsestr){
                    var str = isJSON(responsestr);
    				if(str==1){
                        var obj=JSON.parse(responsestr);
                        if(obj.s==10){
                            layer.msg(obj.msg,{shade:0.6,time:1000,end:function(){
                                window.location.href=window.location.href;
                            }});
                        }else{
                            layer.alert(obj.msg,{shade:0.2});return false;
                        }
    				}else{
    					layer.alert('系统错误，请联系管理员',{icon: 2,shade:0.8,title:"错误提示:"});
    				}
    			},
    			error:function(){
    				layer.alert('系统繁忙，请稍后再试！',{icon: 2,shade:0.8,title:"错误提示:"});
    			}
    		});
        });
	})

	function isJSON(str) {
		if (typeof str == 'string') {
			try{
				var obj=JSON.parse(str);
				if(str.indexOf('{')>-1){
					return 1;
				}else{
					return 0;
				}
			}catch(e){
				return 0;
			}
		}
		return 0;
	}
</script>
